﻿using System;
using System.Windows;
using System.Windows.Data;

namespace HBCode.Converters
{
    public class ResourceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string resultValue = string.Empty;
            if (value is string)
                resultValue = System.Convert.ToString(Application.Current.TryFindResource(value.ToString()));

            if (string.IsNullOrWhiteSpace(resultValue))
                return value;

            return resultValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException("Generally we dont change visibility from UI by user");
        }
    }
}
